package storage.file;

//import java.io.RandomAccessFile;
import java.nio.ByteBuffer;

//import error.EBFileException;

public abstract class AbstractFileManager {
	
	/**
	 * Get the corresponding file name from a global block number.
	 * @param blockNumber
	 * @return file name if existed, <b>null</b> otherwise.
	 */
	public abstract String getFileName(int blockNumber);
	
	/**
	 * Get the corresponding block's offset in the file.
	 * @param blockNumber
	 * @return a non-negative offset if existed, <b>-1</b> otherwise.
	 */
	public abstract int getOffsetInFile(int blockNumber);
	
	/**
	 * Get a block using a global block number.
	 * @param blockNumber
	 * @return a corresponding BlockID object if existed, <b>null</b> otherwise.
	 */
	public final BlockID getBlock(int blockNumber) {
		return new BlockID(getFileName(blockNumber), getOffsetInFile(blockNumber));
	}
	
//	public abstract int read(RandomAccessFile file, int offset, int length, Byteb)
	public abstract Block read(BlockID blockID);
	public abstract void write(BlockID blockID, Block block);
	
    //-----------------------------------------------------------------SHADOW
	public abstract void read(BlockID blockID, ByteBuffer byteBuffer);
	public abstract void write(BlockID blockID, ByteBuffer byteBuffer);
	public abstract BlockID append(String fileName, ByteBuffer byteBuffer);
	
}